/*
 * @Author: your name
 * @Date: 2020-07-30 14:47:57
 * @LastEditTime: 2020-08-03 15:52:35
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \dcg-vue-init\src\store\modules\user.js
 */

const state = {
  tabs: []
}

const mutations = {
  addTabs(state, payload) {
    if (
      state.tabs.every(v => {
        return v.name !== payload.name
      })
    ) {
      state.tabs.push(payload)
    }
  },
  removeTabs(state, payload) {
    state.tabs = state.tabs.filter(v => v.name !== payload)
  }
}

const actions = {
  addTabs({ commit }, payload) {
    commit('addTabs', payload)
  },
  removeTabs({ commit }, payload) {
    commit('removeTabs', payload)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
